<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>华氏温度转换器</title>

    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f2f2f2;
        }

        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 350px;
            text-align: center;
        }

        h1 {
            margin-bottom: 20px;
            color: #333;
        }

        input {
            padding: 10px;
            width: 80%;
            margin-bottom: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
        }

        button {
            padding: 10px 20px;
            border: none;
            background-color: #2196F3;
            color: white;
            font-size: 16px;
            cursor: pointer;
            border-radius: 5px;
            margin-bottom: 15px;
        }

        button:hover {
            background-color: #0b7dda;
        }

        .result {
            margin-top: 20px;
            font-size: 18px;
            color: #333;
            padding: 10px;
            border-radius: 5px;
            background-color: #f9f9f9;
        }

        .reference {
            margin-top: 20px;
            border-top: 1px solid #eee;
            padding-top: 15px;
        }

        .reference h3 {
            margin-bottom: 10px;
            font-size: 16px;
            color: #555;
        }

        .reference-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            font-size: 14px;
        }

        .reference-table th,
        .reference-table td {
            padding: 8px;
            text-align: center;
            border-bottom: 1px solid #ddd;
        }

        .reference-table th {
            background-color: #f2f2f2;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>华氏温度转换器</h1>

        <!-- 用户输入华氏度 -->
        <input type="number" id="fahrenheit" placeholder="请输入华氏度" />

        <!-- 转换按钮 -->
        <button id="convertBtn">转换为摄氏度</button>

        <!-- 显示转换后的结果 -->
        <div class="result" id="result">转换结果将显示在这里</div>

        <!-- 常见温度参考值 -->
        <div class="reference">
            <h3>常见温度参考值</h3>
            <table class="reference-table">
                <tr>
                    <th>场景</th>
                    <th>华氏度(°F)</th>
                    <th>摄氏度(°C)</th>
                </tr>
                <tr>
                    <td>水的冰点</td>
                    <td>32</td>
                    <td>0</td>
                </tr>
                <tr>
                    <td>室温</td>
                    <td>68-72</td>
                    <td>20-22</td>
                </tr>
                <tr>
                    <td>人体温度</td>
                    <td>98.6</td>
                    <td>37</td>
                </tr>
                <tr>
                    <td>水的沸点</td>
                    <td>212</td>
                    <td>100</td>
                </tr>
            </table>
        </div>
    </div>

    <script>
        // 华氏度转摄氏度的转换函数 (保持原有实现)
        const fahrenheitToCelsius = degrees => ((degrees - 32) * 5) / 9;

        // 获取DOM元素
        const fahrenheitInput = document.getElementById('fahrenheit');
        const convertButton = document.getElementById('convertBtn');
        const resultDiv = document.getElementById('result');

        // 点击按钮时触发的事件
        convertButton.addEventListener('click', () => {
            const fahrenheit = parseFloat(fahrenheitInput.value);

            // 确保输入的是有效数字
            if (!isNaN(fahrenheit)) {
                const celsius = fahrenheitToCelsius(fahrenheit);
                resultDiv.textContent = `${fahrenheit}°F = ${celsius.toFixed(2)}°C`;

                // 根据温度范围添加一些实用的描述
                if (celsius <= 0) {
                    resultDiv.textContent += " (冰点或以下，非常寒冷)";
                } else if (celsius > 0 && celsius < 10) {
                    resultDiv.textContent += " (很冷)";
                } else if (celsius >= 10 && celsius < 20) {
                    resultDiv.textContent += " (凉爽)";
                } else if (celsius >= 20 && celsius < 30) {
                    resultDiv.textContent += " (舒适温度)";
                } else if (celsius >= 30 && celsius < 40) {
                    resultDiv.textContent += " (炎热)";
                } else {
                    resultDiv.textContent += " (非常热)";
                }
            } else {
                resultDiv.textContent = "请输入有效的华氏度值";
            }
        });

        // 添加按回车键也能触发转换
        fahrenheitInput.addEventListener('keypress', (event) => {
            if (event.key === 'Enter') {
                convertButton.click();
            }
        });
    </script>

</body>

</html>